<template>
  <div class="index">
    <div class="seat" ref="seat">
      <Sidebar></Sidebar>
    </div>
    <div class="main" ref="main">
      <div class="mask" v-if="mask" @click="closeMask"></div>
      <router-view v-if="isRouterAlive"></router-view>
    </div>
  </div>
</template>

<script>
import Sidebar from "../components/Sidebar.vue";
export default {
  name: "index",
  data() {
    return {
      isRouterAlive: true,
      mask: false,
    };
  },
  components: {
    Sidebar,
  },
  provide() {
    return {
      reload: this.reload,
    };
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true;
      });
    },
    closeMask() {
      this.$store.commit("maskStatus_change", false);
      this.$router.go(-1);
    },
  },
  computed: {
    sidebarStatus() {
      return this.$store.state.sidebar;
    },
    maskStatus() {
      return this.$store.state.mask;
    },
  },
  watch: {
    sidebarStatus: {
      handler(newVal, oldVal) {
        const seat = this.$refs.seat;
        const main = this.$refs.main;
        seat.classList.toggle("close");
        main.classList.toggle("close");
      },
      deep: true,
    },
    maskStatus: {
      handler(newVal, oldVal) {
        this.mask = newVal;
      },
      deep: true,
    },
  },
};
</script>

<style scoped>
.index {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.seat {
  box-sizing: border-box;
  float: left;
  width: 250px;
  height: 100%;
  transition: all 0.5s ease;
}
.seat.close {
  width: 82px;
  transition: all 0.4s ease;
}
.main {
  box-sizing: border-box;
  float: right;
  width: calc(100% - 250px);
  height: 100%;
  transition: all 0.5s ease;
}
.main.close {
  width: calc(100% - 82px);
  transition: all 0.4s ease;
}
.mask {
  position: absolute;
  width: calc(100% - 250px);
  height: 100%;
  backdrop-filter: blur(5px);
  z-index: 99;
}
</style>